package com.huike.web.controller.report;


import com.huike.clues.domain.vo.IndexStatisticsVo;
import com.huike.common.core.domain.AjaxResult;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import com.huike.report.domain.vo.IndexVo;
import com.huike.report.domain.vo.TopVo;
import com.huike.report.service.IReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/index")
@Slf4j
public class IndexController {

    @Autowired
    private IReportService iReportService;

    /**
     * 首页数据统计接口
     *
     * @return
     */
    @GetMapping
    public AjaxResult index(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime,
                            Integer deptId) {
        log.info("index controller=================>beginCreateTime:{},endCreateTime:{},deptId:{}", beginCreateTime, endCreateTime, deptId);
        IndexVo indexVo = iReportService.indexTodoInfo(beginCreateTime, endCreateTime);
        return AjaxResult.success(indexVo);
    }

    /**
     * 线索转化龙虎榜
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @param deptId
     * @return
     */
    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistic(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                     @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime,
                                     Integer deptId) {
        log.info("salesStatistic controller=================>beginCreateTime:{},endCreateTime:{},deptId:{}", beginCreateTime, endCreateTime, deptId);
        List<TopVo> indexStatisticsVos = iReportService.salesStatistic(beginCreateTime, endCreateTime, deptId);
        return AjaxResult.success(indexStatisticsVos);
    }

    /**
     * 商机转化龙虎榜
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @param deptId
     * @return
     */
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime,
            Integer deptId) {
        log.info("salesStatistic controller=================>beginCreateTime:{},endCreateTime:{},deptId:{}", beginCreateTime, endCreateTime, deptId);
        List<TopVo> indexStatisticsVos = iReportService.businessChangeStatistics(beginCreateTime, endCreateTime, deptId);
        return AjaxResult.success(indexStatisticsVos);
    }
}